//
//  ScoreViewController.m
//  BallRankingProject
//
//  Created by lanou3g on 15/5/31.
//  Copyright (c) 2015年 luojian. All rights reserved.
//

#import "ScoreViewController.h"
#import "UIImageView+WebCache.h"
@interface ScoreViewController ()

@end

@implementation ScoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _love=0;
    /**
     *  /
     */
    
    self.navigationController.navigationBar.translucent = NO;
    [self getImage];
    self.tableView.bounces=NO;
    UIBarButtonItem *leftBI=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Back"] style:(UIBarButtonItemStyleDone) target:self action:@selector(goBackTo:)];
    self.navigationItem.leftBarButtonItem=leftBI;
    leftBI.tintColor=[UIColor whiteColor];
    
}
- (void)goBackTo:(UIBarButtonItem *)BI
{

[self.navigationController popViewControllerAnimated:YES];

}



- (void)getImage
{
    //self.view.backgroundColor=[UIColor colorWithRed:0.866 green:0.477 blue:1.000 alpha:1.000];
    self.allArray=[NSMutableArray array];
    NSString *str=[NSString stringWithFormat:@"%@%@",MICS,_string];
    NSURL *url=[NSURL URLWithString:str];
    NSData *data=[NSData dataWithContentsOfURL:url];
    if (data==nil) {
        
        return ;
    }
    NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
   
    NSDictionary *dic2=[dic objectForKey:@"result"];
   self.titltDic=[dic2 objectForKey:@"info"];
    NSArray *array=[dic2 objectForKey:@"schedule"];
    for (NSDictionary *dict in array) {
        Integral *integral=[[Integral alloc] init];
        [integral setValuesForKeysWithDictionary:dict];
        [_allArray addObject:integral];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return _allArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    IntegralViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
    if (!cell) {
        cell=[[IntegralViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"myCell"];
    }
    Integral *integal=_allArray[indexPath.row];
    cell.begin_timeLable.text=integal.begin_time;
    cell.is_winLable.text=integal.is_win;
    cell.scoreLable.text=integal.score;
    cell.vs_team_nameLable.text=integal.vs_team_name;
    NSString *string=integal.vs_team_logo;
    [cell.vs_team_logoImageview sd_setImageWithURL:[NSURL URLWithString:string] placeholderImage:[UIImage imageNamed:@"placeHold"]];
    cell.sideLable.text=integal.side;
    cell.stageLable.text=integal.stage;
    
    
    
   
   // cell.frame.size.width=80;
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{

return @" ";

}
- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return 150;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 160;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView *headView=[[UIView alloc] initWithFrame:CGRectMake(0,0,CGRectGetWidth(tableView.frame), 160)];
    //headView=tableView.tableHeaderView;
    headView.backgroundColor=[UIColor colorWithRed:0.224 green:0.380 blue:0.599 alpha:1.000];
    UIImageView *headImageView=[[UIImageView alloc] initWithFrame:CGRectMake(5, (CGRectGetHeight(headView.frame)-CGRectGetWidth(headView.frame)/3)/2, CGRectGetWidth(headView.frame)/3, CGRectGetWidth(headView.frame)/3)];
   
    UILabel *full_nameLable=[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(headImageView.frame)+10, 5, CGRectGetWidth(headImageView.frame)/3*2, CGRectGetHeight(headView.frame)/3)];
    UILabel *market_valuesLable=[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(headImageView.frame)+10, CGRectGetHeight(full_nameLable.frame)+5, CGRectGetWidth(headView.frame)/3*2, CGRectGetHeight(headView.frame)/3)];
    [headView addSubview:full_nameLable];
    [headView addSubview:market_valuesLable];
    [headView addSubview:headImageView];
    full_nameLable.text=[_titltDic objectForKey:@"full_name"];
    market_valuesLable.text=[_titltDic objectForKey:@"market_values"];
    NSString *string=[_titltDic objectForKey:@"logo"];
    
    [headImageView sd_setImageWithURL:[NSURL URLWithString:string] placeholderImage:[UIImage imageNamed:@"placeHold"]];
    //[headImageView sd_setImageWithURL:[NSURL URLWithString:string]];

    return headView;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
